new Vue({
  el: '#app',
  data: {
    active: 3,
    loading: true,
    user: {}
  },
  mounted () {
    this.loading = false
    this.main()
  },
  methods: {
    onClickLeft: function () {
      history.go(-1)
    },
    async main() {
      let user = await $http.get('/api/user/getUserInfo')
      this.user = user.data.data

      if(!this.user.avatar) {
        this.user.avatar = '../image/img.png'
      }
    },
    onSubmit(formName) {
      this.$refs[formName].validate(async (valid) => {
        if (!valid) { return false; }
        let res = await $http.post('/api/user/login', this.form)
        if (res.data.code != 1) { return this.$toast(res.data.msg) }

        if(this.save) {
          $utils.setLocalStorage('account', JSON.stringify(this.form))
        }

        this.$toast.success({
          message: '登录成功',
          onClose: function () { window.location.href = './my.html' }
        })
      })

    },
  }
})